package com.project.action;

import java.io.IOException;

import mvc.core.File;
import mvc.core.Response;
import mvc.core.annotation.Action;
import mvc.core.annotation.GET;
import mvc.core.annotation.Inject;
import mvc.core.annotation.Mapping;
import mvc.core.annotation.POST;
import mvc.core.log.Logger;
import mvc.core.util.Util;

import com.project.service.MyService;

/**
 * Action
 * 
 * @author liuzy
 * @version 2015年5月13日
 */
@Action
@Mapping("/myAction")
public class MyAction {
	
	private Logger logger = Logger.getLogger(MyAction.class);
	
	public Response response = new Response();
	
	@Inject
	private MyService service;
	
	@GET
	@Mapping("/login")
	public Response login() {
		logger.info("MyAction login()");
		boolean flag = service.login("liuzy", "111111");
		if (flag)
			response.setContent("登陆成功");
		else
			response.setContent("登陆失败");
		return response;
	}
	
	@POST
	@Mapping("/manager")
	public Response manager() {
		logger.info("MyAction manager()");
		return new Response(service.manager());
	}

	@Mapping("/add")
	public Response add() {
		logger.info("MyAction add()");
		int i = service.add("xhy", "123");
		return new Response(i+"行受影响");
	}

	@Mapping("/download")
	public File download() {
		logger.info("MyAction download()");
		String fileName = "test.txt";
		byte[] fileBytes = null;
		try {
			fileBytes = Util.getFileBytes(fileName);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new File(fileName, fileBytes);
	}
}
